#include <esp_system.h>

//int exampl[15][16]=	   {{},
///* - */					{},
///* | */					{},
///* | */					{},
///* | */					{},
///* H */					{},
///* I */					{},
///* G */					{},
///* H */					{},
///* T */					{},
///* | */					{},
///* | */					{},
///* | */					{},
///* - */					{},
///*Colors:*/				{}};
//length					{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}*/

/*int emptyI[15][16]=  {{},
						{},
						{},
						{},
						{},
						{},
						{},
						{},
						{},
						{},
						{},
						{},
						{},
						{},
						{}};*/
//						{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}

int mario1[15][16] = {{0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 2, 2, 2, 0},
					  {0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 0},
					  {0, 0, 0, 0, 3, 3, 3, 2, 2, 4, 2, 0, 1, 1, 1, 0},
					  {0, 0, 0, 3, 2, 3, 2, 2, 2, 4, 2, 2, 2, 1, 1, 0},
					  {0, 0, 0, 3, 2, 3, 3, 2, 2, 2, 4, 2, 2, 2, 1, 0},
					  {0, 0, 0, 3, 3, 2, 2, 2, 2, 4, 4, 4, 4, 1, 0, 0},
					  {0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 1, 1, 0, 0},
					  {2, 2, 1, 1, 1, 1, 5, 1, 1, 1, 5, 1, 1, 0, 0, 3},
					  {2, 2, 1, 1, 1, 1, 1, 5, 1, 1, 1, 5, 0, 0, 3, 3},
					  {0, 0, 0, 0, 1, 1, 1, 5, 5, 5, 5, 6, 5, 5, 3, 3},
					  {0, 0, 0, 0, 0, 5, 5, 5, 6, 5, 5, 5, 5, 5, 3, 3},
					  {0, 0, 0, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 3},
					  {0, 0, 3, 3, 3, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0},
					  {0, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
					  {0 + 0x8000, 992 + 0x8000, 30 * 32 + 28 + 2 * 1024 + 0x8000 /*960+14+8192+1024+0x8000*/, 11 * 32 + 0x8000, 0 + 0x8000, 31744 + 0x8000, 1023 + 0x8000}};

int luigi[15][16] = {{0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 2, 2, 2, 0},
					 {0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 0},
					 {0, 0, 0, 0, 3, 3, 3, 2, 2, 4, 2, 0, 1, 1, 1, 0},
					 {0, 0, 0, 3, 2, 3, 2, 2, 2, 4, 2, 2, 2, 1, 1, 0},
					 {0, 0, 0, 3, 2, 3, 3, 2, 2, 2, 4, 2, 2, 2, 1, 0},
					 {0, 0, 0, 3, 3, 2, 2, 2, 2, 4, 4, 4, 4, 1, 0, 0},
					 {0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 1, 1, 0, 0},
					 {2, 2, 1, 1, 1, 1, 5, 1, 1, 1, 5, 1, 1, 0, 0, 3},
					 {2, 2, 1, 1, 1, 1, 1, 5, 1, 1, 1, 5, 0, 0, 3, 3},
					 {0, 0, 0, 0, 1, 1, 1, 5, 5, 5, 5, 6, 5, 5, 3, 3},
					 {0, 0, 0, 0, 0, 5, 5, 5, 6, 5, 5, 5, 5, 5, 3, 3},
					 {0, 0, 0, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 3},
					 {0, 0, 3, 3, 3, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0},
					 {0, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
					 {0 + 0x8000, 20 + 0x8000, 30 * 32 + 28 + 2 * 1024 + 0x8000 /*992+15+8192+1024+0x8000*/, 11 * 32 + 0x8000, 0 + 0x8000, 0xFFFF, 1023 + 0x8000}};

int questBox[15][16] = {{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
						{1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0},
						{1, 2, 0, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 0, 2, 0},
						{1, 2, 2, 2, 1, 1, 0, 0, 0, 1, 1, 2, 2, 2, 2, 0},
						{1, 2, 2, 2, 1, 1, 0, 2, 2, 1, 1, 0, 2, 2, 2, 0},
						{1, 2, 2, 2, 1, 1, 0, 2, 2, 1, 1, 0, 2, 2, 2, 0},
						{1, 2, 2, 2, 2, 0, 0, 2, 1, 1, 1, 0, 2, 2, 2, 0},
						{1, 2, 2, 2, 2, 2, 2, 1, 1, 0, 0, 0, 2, 2, 2, 0},
						{1, 2, 2, 2, 2, 2, 2, 1, 1, 0, 2, 2, 2, 2, 2, 0},
						{1, 2, 2, 2, 2, 2, 2, 2, 0, 0, 2, 2, 2, 2, 2, 0},
						{1, 2, 2, 2, 2, 2, 2, 1, 1, 2, 2, 2, 2, 2, 2, 0},
						{1, 2, 2, 2, 2, 2, 2, 1, 1, 0, 2, 2, 2, 2, 2, 0},
						{1, 2, 0, 2, 2, 2, 2, 2, 0, 0, 2, 2, 2, 0, 2, 0},
						{1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0},
						{0, 0, 0, 1002 + 0x8000, 1002 + 0x8000, 1002 + 0x8000, 1023 + 0x8000, 1002 + 0x8000, 10 * 32 + 8 + 8 * 1024 + 0x8000}};

int link1[15][16] = {{0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0},
					 {0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0},
					 {0, 0, 2, 0, 1, 3, 3, 3, 3, 3, 3, 1, 0, 2, 0, 0},
					 {0, 0, 2, 0, 3, 3, 3, 3, 3, 3, 3, 3, 0, 2, 0, 0},
					 {0, 0, 2, 2, 3, 2, 1, 2, 2, 1, 2, 3, 2, 2, 0, 0},
					 {0, 0, 2, 2, 3, 2, 3, 2, 2, 3, 2, 3, 2, 2, 0, 0},
					 {0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 0, 0},
					 {0, 0, 0, 0, 1, 2, 2, 3, 3, 2, 2, 1, 3, 3, 0, 0},
					 {0, 0, 3, 3, 3, 3, 3, 2, 2, 2, 1, 1, 1, 2, 0, 0},
					 {0, 3, 3, 2, 3, 3, 3, 3, 1, 1, 1, 1, 1, 2, 0, 0},
					 {0, 3, 2, 2, 2, 3, 3, 2, 3, 3, 1, 1, 3, 0, 0, 0},
					 {0, 3, 3, 2, 3, 3, 3, 2, 1, 3, 3, 3, 2, 0, 0, 0},
					 {0, 3, 3, 2, 3, 3, 3, 2, 3, 3, 1, 1, 1, 0, 0, 0},
					 {0, 3, 3, 3, 3, 3, 3, 2, 2, 1, 1, 3, 0, 0, 0, 0},
					 {0, 31 + 0x8000, 30 * 32 + 28 + 2 * 1024 + 0x8000, 11 * 32 + 0x8000}};

int link2[15][16] = {{0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0},
					 {0, 0, 0, 3, 1, 1, 3, 1, 1, 1, 3, 3, 3, 0, 0, 0},
					 {0, 0, 3, 1, 1, 3, 2, 3, 1, 3, 3, 3, 3, 3, 0, 0},
					 {0, 3, 1, 3, 1, 3, 2, 3, 3, 3, 3, 3, 3, 3, 0, 0},
					 {0, 3, 3, 3, 1, 3, 2, 2, 3, 3, 2, 2, 3, 0, 0, 0},
					 {0, 0, 0, 3, 3, 3, 2, 2, 3, 2, 3, 2, 3, 3, 3, 0},
					 {0, 0, 0, 0, 3, 3, 2, 2, 3, 2, 3, 2, 2, 2, 3, 0},
					 {0, 0, 0, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, 0},
					 {0, 0, 0, 0, 0, 3, 3, 2, 2, 2, 2, 3, 3, 0, 0, 0},
					 {0, 0, 0, 0, 3, 3, 3, 3, 2, 2, 2, 2, 3, 0, 0, 0},
					 {0, 0, 0, 3, 1, 1, 1, 3, 2, 3, 3, 3, 0, 0, 0, 0},
					 {0, 0, 0, 3, 3, 1, 1, 1, 3, 3, 2, 3, 0, 0, 0, 0},
					 {0, 0, 0, 3, 3, 3, 1, 1, 1, 3, 1, 3, 0, 0, 0, 0},
					 {0, 0, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 3, 3, 0, 0},
					 {0, 31 + 0x8000, 30 * 32 + 28 + 2 * 1024 + 0x8000, 11 * 32 + 0x8000}};

int coin[15][16] = {{0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0},
					{0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0},
					{0, 0, 0, 0, 0, 2, 2, 1, 1, 2, 2, 0, 0, 0, 0, 0},
					{0, 0, 0, 0, 2, 2, 1, 2, 2, 0, 2, 2, 0, 0, 0, 0},
					{0, 0, 0, 0, 2, 2, 1, 2, 2, 0, 2, 2, 0, 0, 0, 0},
					{0, 0, 0, 0, 2, 2, 1, 2, 2, 0, 2, 2, 0, 0, 0, 0},
					{0, 0, 0, 0, 2, 2, 1, 2, 2, 0, 2, 2, 0, 0, 0, 0},
					{0, 0, 0, 0, 2, 2, 1, 2, 2, 0, 2, 2, 0, 0, 0, 0},
					{0, 0, 0, 0, 2, 2, 1, 2, 2, 0, 2, 2, 0, 0, 0, 0},
					{0, 0, 0, 0, 2, 2, 1, 2, 2, 0, 2, 2, 0, 0, 0, 0},
					{0, 0, 0, 0, 2, 2, 1, 2, 2, 0, 2, 2, 0, 0, 0, 0},
					{0, 0, 0, 0, 0, 2, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0},
					{0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0},
					{0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0},
					{0, 0, 0, 1002 + 0x8000, 1002 + 0x8000, 1002 + 0x8000, 1023 + 0x8000, 1002 + 0x8000, 10 * 32 + 8 + 8 * 1024 + 0x8000}};

int pacman[15][16] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
					  {0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0},
					  {0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 0, 0, 0, 0, 0},
					  {0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 0, 0, 0, 0},
					  {0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 0, 0, 0, 0},
					  {1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 0, 0, 0},
					  {1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 0, 0, 0},
					  {1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 4, 4, 3, 0, 5, 5},
					  {1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 3, 0, 5, 5},
					  {1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 0, 0, 0},
					  {0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 0, 0, 0, 0},
					  {0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 0, 0, 0, 0},
					  {0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 0, 0, 0, 0, 0},
					  {0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0},
					  {31 * 32 + 31 + 0x8000, 0, 0xFFFF}};

int mario3[15][16] = {{0, 0, 1, 1, 0, 0, 2, 2, 2, 2, 0, 1, 0, 0, 0, 0},
					  {0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 0, 0, 0, 0},
					  {0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
					  {0, 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0},
					  {0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0},
					  {0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0},
					  {0, 2, 2, 2, 2, 2, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0},
					  {0, 2, 2, 2, 2, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0},
					  {0, 2, 2, 2, 2, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0},
					  {0, 0, 2, 2, 2, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0},
					  {0, 0, 2, 2, 2, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0},
					  {0, 0, 0, 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0},
					  {0, 0, 0, 0, 0, 0, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0},
					  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
					  {0, 30 * 32 + 28 + 2 * 1024 + 0x8000, 11 * 32 + 0x8000}};

int megaman[15][16] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0},
					   {0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 2, 2, 0, 0, 0, 0},
					   {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
					   {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 2, 2, 1, 0, 0},
					   {0, 0, 0, 0, 2, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0},
					   {0, 0, 0, 0, 2, 1, 1, 3, 4, 4, 4, 1, 1, 4, 0, 0},
					   {0, 0, 0, 0, 2, 1, 3, 4, 4, 0, 0, 3, 0, 4, 0, 0},
					   {0, 0, 0, 0, 0, 1, 3, 4, 4, 0, 0, 3, 0, 4, 0, 0},
					   {0, 0, 0, 0, 0, 1, 3, 3, 4, 4, 4, 3, 4, 4, 0, 0},
					   {0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 0, 3, 0, 0, 0},
					   {0, 1, 2, 2, 2, 2, 0, 3, 3, 3, 3, 3, 0, 2, 2, 1},
					   {0, 1, 1, 2, 2, 2, 2, 0, 0, 0, 0, 0, 2, 2, 1, 1},
					   {1, 1, 1, 2, 0, 2, 2, 2, 2, 2, 2, 2, 0, 2, 1, 1},
					   {1, 1, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 1},
					   {0, (31 * 1024 + 0x8000), (31 * 1024 + 31 + 0x8000), (30 * 32 + 28 + 2 * 1024 + 0x8000), 0xFFFF}};

int getIconPixel(char actChar, int xMod, int yMod, int colorCycle)
{
	int colorNumber = 0;
	if (actChar == ';')
	{
		colorNumber = coin[yMod][xMod];
		return coin[14][colorNumber * 3 + ((colorCycle) % 3)];
	}
	if (actChar == '/')
	{
		colorNumber = megaman[yMod][xMod];
		return megaman[14][colorNumber];
	}
	if (actChar == '$')
	{
		colorNumber = mario1[yMod][xMod];
		return mario1[14][colorNumber];
	}
	if (actChar == '%')
	{
		colorNumber = luigi[yMod][xMod];
		return luigi[14][colorNumber];
	}
	if (actChar == '"')
	{
		colorNumber = mario3[yMod][xMod];
		return mario3[14][colorNumber];
	}
	if (actChar == '=')
	{
		colorNumber = link1[yMod][xMod];
		return link1[14][colorNumber];
	}
	if (actChar == '+')
	{
		colorNumber = link2[yMod][xMod];
		return link2[14][colorNumber];
	}
	if (actChar == '}')
	{
		colorNumber = questBox[yMod][xMod];
		return questBox[14][colorNumber * 3 + ((colorCycle) % 3)];
	}
	if (actChar == '{')
	{
		colorNumber = pacman[yMod][xMod];
		//printf("mod3%d\n",(change/2)%3);
		if (colorNumber == 0)
			return pacman[14][1];
		else if (colorNumber == 1)
			return pacman[14][0];
		else if (colorNumber == 5)
			return pacman[14][2];
		else
		{
			if (colorCycle % 3 == 0)
			{
				if (colorNumber == 4)
					return pacman[14][2];
				if (colorNumber == 2)
					return pacman[14][1];
				if (colorNumber == 3)
					return pacman[14][1];
			}
			else if (colorCycle % 3 == 1)
			{
				if (colorNumber == 4)
					return pacman[14][2];
				if (colorNumber == 2)
					return pacman[14][0];
				if (colorNumber == 3)
					return pacman[14][1];
			}
			else
			{
				if (colorNumber == 4)
					return pacman[14][0];
				if (colorNumber == 2)
					return pacman[14][0];
				if (colorNumber == 3)
					return pacman[14][0];
			}
		}
	}
	return 992;
}